<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>变更管理</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="变更管理" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox">
                            <div class="label">承租人</div>
                            <div class="field">
                                <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">合同号</div>
                            <div class="field">
                                <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">项目类型</div>
                            <div class="field">
                                <select name="prjTypCd"  id="prjTypCd" >
                                    <option value="  " selected="selected">--请选择--</option>
                                    <c:forEach items="${prjTypCdList}" var="opt">
                                        <option value="${opt.key}">${opt.value}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">所属机构</div>
                            <div class="field">
                                <select name="buOrgCd" id="buOrgCd">
                                    <option value=" " seleted>--请选择--</option>
                                    <c:forEach items="${orgList }" var="org">
                                        <c:if test="${currentBuOrgCd == org.key }">
                                            <option value="${org.key }" selected>${org.value }</option>
                                        </c:if>
                                        <c:if test="${currentBuOrgCd != org.key }">
                                            <option value="${org.key }">${org.value }</option>
                                        </c:if>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">是否资管</div>
                            <div class="field">
                                <select name="isInsBiz" id="isInsBiz" >
                                    <option value=" " checked >--请选择--</option>
                                    <c:forEach items="${yesOrNoList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">是否厂商</div>
                            <div class="field">
                                <select name="isSplMfr" id="isSplMfr" >
                                    <option value=" " checked >--请选择--</option>
                                    <c:forEach items="${yesOrNoList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">第三方机构</div>
                            <div class="field">
                                <select name="insCode" id="insCode">
                                    <option value="  " selected="selected">--请选择--</option>
                                    <c:forEach items="${friBaseList}" var="fri">
                                        <option value="${fri.insCode}">${fri.fundRasInsNm}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">变更类型</div>
                            <div class="field">
                                <select name="changeTypeCd" id="changeTypeCd">
                                    <option value="  " selected="selected">--请选择--</option>
                                    <c:forEach items="${changeTypeList}" var="change">
                                        <option value="${change.key}">${change.value}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="clearFix"></div>
                        <div class="btnsBox">
                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                            <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                            <span id="addBtn" class="sq-button sq-button-round" onclick="changeApply()">退车</span>
                            <c:if test="${isShowHC == '1'}">
                                <span id="addBtn2" class="sq-button sq-button-round" onclick="changeApplyForHC()">换车</span>
                            </c:if>
                        </div>
                    </div>
                </form>
            </div>
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <div tabid="tabB" title="流程跟踪" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
    </div>
</div>



<script type="text/javascript">
    var grid = null;
    var pageInTab = null;
    var pageInApp = {};
    $(function () {
        initTab();

        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/changeapply/prjPrdChangeApply/initList.do',
            method: 'get',
            columns: [
                {display: '承租人名称', name: 'cstNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '合同号', name: 'lsCntNo', minWidth: 100, align: 'center', enabledSort: false },
                {display: '支付表号', name: 'paySchNo', minWidth: 100, align: 'center', enabledSort: false },
                {display: '支付表状态', name: 'prdStsCdNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '项目类型', name: 'prjTypCdNm', minWidth: 100, align: 'center', enabledSort: false },
                { display: '是否资管', name: 'isInsBiz', minWidth: 100 , align: 'center', enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        if (rowdata.isInsBiz == 1) {
                            return "是";
                        } else if (rowdata.isInsBiz == 0) {
                            return "否";
                        }
                    }
                },
                { display: '是否厂商', name: 'isSplMfr', minWidth: 100 , align: 'center', enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        if (rowdata.isSplMfr == 1) {
                            return "是";
                        } else if (rowdata.isSplMfr == 0) {
                            return "否";
                        }
                    }
                },
                {display: '变更类型', name: 'changeTypeCdNm', minWidth: 100 , align: 'center', enabledSort:true },
                {display: '第三方机构', name: 'fundRasInsNm', width: 150, align: 'center', enabledSort: false },
                {display: '所属机构', name: 'buOrgCdNm', width: 150, align: 'center', enabledSort: false },
                {display: '省公司', name: 'prOrgCdNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '分公司', name: 'cyOrgCdNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '租赁期次', name: 'lsPd', minWidth: 100, align: 'center', enabledSort: false },
                {display: '已还期次', name: 'payPd', minWidth: 100, align: 'center', enabledSort: false },
                { display: '上牌状态', name: 'licDt', minWidth: 100,align:'center',
                    render: function (rowdata, rowindex, value, column) {
                        var dt = rowdata.licDt==null?" ":rowdata.licDt;
                        if(dt!=" "){
                            if(rowdata.licAudStsCd==FlowConstant.FLOW_CHECK_STATE_PASS){
                                return "已上牌";
                            }
                            if(rowdata.licAudStsCd==FlowConstant.FLOW_CHECK_STATE_NON){
                                return "未上牌";
                            }
                        } else{
                            return "未上牌";
                        }
                    },
                    enabledSort:true},
                {display: '抵押状态', name: 'guarStsCdNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '申请单号', name: 'proNo', minWidth: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (value && value != "null") {
                            h += '<a href="javascript:showFlow(';
                            h += "'" + rowdata.proInsId + "',";
                            h += "'" + rowdata.audStsCd + "',";
                            h += "'" + rowdata.changeTypeCd + "',";
                            h += "'" + rowdata.id + "'";
                            h += ')">' + value + '</a>'
                        }
                        return h;
                    }
                },
                {display: '审核状态', name: 'audStsCdNm', minWidth: 100, align: 'center', enabledSort: false },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        var callback = function () {
            grid.reload();
        };

    });

    var loadedTabs = [];
    //初始化Tab页签
    function initTab(){
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function(tabid) {
                var selectedRows = grid.getSelectedRows();
                if(tabid!="tabA"){
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }
                }
            },
            onAfterSelectTabItem: function(tabid) {
                var selectedRows = grid.getSelectedRows();
                if(tabid!="tabA"){
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }else{
                        if (loadedTabs.indexOf(selectedRows[0].prjId)<0) {
                            loadedTabs = [];
                            loadedTabs.push(selectedRows[0].prjId);
                            switch (tabid){
                                case "tabB":
                                    pageInTab.setTabItemSrc(tabid, "<%=path%>/project/audit/toProjectFlowPage.do?prjId="+selectedRows[0].prjId+"&prjTypCd="+selectedRows[0].prjTypCd);
                                    break;
                            }
                        }
                        SetIframe_height();
                    }
                }
             }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    }

    //退车页面
    function changeApply() {
        var callback = function(){
            grid.reload();
        }
        var userId = ${currentUsrId};
        var changeTypeCd = '1';
        $.ligerDialog.open({
            title: '申请退车',
            height: 500,
            width: 850,
            url: '<%=path%>/changeapply/prjPrdChangeApply/toChangeApplyPage.do?userId=' + userId + '&&changeTypeCd=' + changeTypeCd,
            isResize: true ,
            callback:callback
        });
    }

    //换车页面
    function changeApplyForHC() {
        var callback = function(){
            grid.reload();
        }
        var userId = ${currentUsrId};
        var changeTypeCd = '2';
        $.ligerDialog.open({
            title: '申请换车',
            height: 500,
            width: 850,
            url: '<%=path%>/changeapply/prjPrdChangeApply/toChangeApplyPage.do?userId=' + userId + '&&changeTypeCd=' + changeTypeCd,
            isResize: true ,
            callback:callback
        });
    }

    function showFlow(_pInstId, _audStsCd, changeTypeCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/changeApply/flow/toAdditionalInfoPage.do?isDetail_bk=1@@ctrlKey=3@@changeApplyId=";
        if (changeTypeCd == "2") {
            _formUrl = "/changeApply/flow/toAdditionalInfoPageByHC.do?detailFlag=1@@changeApplyId=";
        }
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_change_apply_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

</script>
</body>
</html>
